package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.MarketCollectMapper;
import com.cskaoyan.model.MarketCollect;
import com.cskaoyan.model.MarketCollectExample;
import com.cskaoyan.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Pudding
 * @Date 2024/6/13 14:07
 */
@Service
public class CollectionServiceImpl implements CollectionService {
    @Autowired
    MarketCollectMapper collectMapper;

    @Override
    public Integer hasCollection(Integer goodsId, byte type, int userId) {
        //收藏类型，如果type=0，则是商品ID，且value_id=goods_id，且user_id为传入的值
        //1. 构造查询条件
        MarketCollectExample example = new MarketCollectExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andTypeEqualTo(type)
                .andValueIdEqualTo(goodsId)
                .andUserIdEqualTo(userId);
        //2. 进行查询
        List<MarketCollect> marketCollects = collectMapper.selectByExample(example);

        return marketCollects != null && marketCollects.size() == 1 ? 1 : 0;
    }
}
